
var _url_ = '../goods/addGoodsInfo.do';
var _url_edit = '../order/updateOrderInfo.do';
var _url_list = '../order/getOrdersList2';
var _url_id = '../goods/getGoodsById';
var _map = {};
///首页
var _pageNum = 1;
var _type ;
var spid="";
var dangqianorder;
  $(function(){
		  getList();
  })
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  })
	  $(".search-btn").click(function(){
			 var tit =  $("#ser-title").val();
			 console.log(tit);
			 delete _map['shopTitle'];
			 if(tit){
				 _map["shopTitle"] = tit;
			 }
			 
			 var sta =$('input[name=status]:checked').val();
			 console.log(sta);
			 _map['state']=sta;
			 
			 var ot =$('input[name=orderType]:checked').val();
			 _map['type']=ot;
			 
			 var ot =$('input[name=payType]:checked').val();
			 _map['payType']=ot;
			 
			 
			 var start =  $("#startTime").val();
			 var end =  $("#endTime").val();
			 _map['startTime'] = start;
			 var end =$("#end").val();
			  if(end){
				  end =  addDate(end,1);
			  }
			 _map['endTime'] = end;
			 
			 
			 _pageNum = 1;
			 getList();
		  });
	  $("body").on("click",".left-type li",function(){
			 var tt = $(this).text();
			 $(this).addClass('lt-li-active').siblings().removeClass('lt-li-active');
			 _map['goodsTypeId'] = $(this).attr('data-status');
			 getList();
	  });
});
  function getList(){
	  _map['pageNum'] = _pageNum;
	  _map['pageSize'] = 100;
//	  _map['pageSize'] = "1";
	  _ajax_get(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			 
			  if(isDigit(v.userName)){
				  v.userName = v.userAddress;
				  v.userAddress = "";
			  }
			 if(v.status ==4 ){
				  stat=4;statStr = '已完成';
			  }else if(v.status ==5|| (v.status >50 && v.status < 59  ||v.status == 6) ){
				  stat=5;statStr = '已取消';
			  }else{
				  stat=0;statStr = '其他';
			  }
			 if(v.payType == 1){
				  payTypeStr = '微信支付';
			  }else{
				  payTypeStr = '现金结算';
			  }
			  html+=' <tr><td>'
	 	             +(i+res.returnObject.startRow)
	 	             +'</td><td>'+v.shopTitle
	 	             +'</td><td>'
	 	             + v.userName
	 	             +' </td><td>'+(v.payPrice/100)
	 	             +' </td> <td >'+payTypeStr
	 	             +' </td> <td >'+(v.type == 1 ? '外卖' : '堂食')
	 	             +' </td> <td >'+statStr
	 	             +' </td> <td >'+formatNullData(v.nickName)
	 	             +' </td> <td >'+v.createTime
	 	             +' </td> <td >'+v.userPhone
	 	             +' </td> <td >'+v.userAddress
	 	             +'</td></tr>';
		  })
		  $(".layui-table tbody").html(html);
	  })
  }
  function alljiedan(){
	  console.log(dangqianorder);
	  $('.layui-btn').addClass('disabled');
	  _ajax_post_token('../order/updateOrderInfoTable.do',{tabId:dangqianorder},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			  layer.msg('操作成功!',{icon:6,time:2000},function(){
				  $('.layui-btn').removeClass('disabled');
				  window.location.reload();
			  });
		  }else{
			  $('.layui-btn').removeClass('disabled');
			  layer.msg('操作失败!',{icon:6,time:2000});
		  }
	  })
  }
  function loadMore(){
	  _pageNum++;
	  getList();
  }
  function getProfitsInfo(){
	  _ajax_post_token('../order/selectOrderProfitToday',{shopId:spid,type:_type2},function(res){
		  console.log(res);
		  var list =  res.returnObject;
		  var profitCount = 0;
		  var totalCount = 0;
		  $.each(list,function(i,v,arr){
    		  console.log(v);
    		  if(v.typeId == 1){
    			  $(".today-profit p").eq(3).find("b").text((v.profit/100).toFixed(2));
    			  $(".today-profit p").eq(4).find("b").text(v.total);
    		  }else{
    			  $(".today-profit p").eq(5).find("b").text((v.profit/100).toFixed(2));
    			  $(".today-profit p").eq(6).find("b").text(v.total);
    		  }
    		  profitCount += Number(v.profit);
    		  totalCount += Number(v.total);
		  })
		  $(".today-profit p").eq(0).find("b").text((profitCount/100).toFixed(2));
		  $(".today-profit p").eq(1).find("b").text(totalCount);
	  })
  }
  
  function selectListByParam(d){
	  for(var key in d){
		  _map[key] =d[key];
		}
	  _pageNum = 1;
	  $(".site-doc-icon").html("");
	  getList();
  }
  
  function printXip(_id){
	  console.log(_id);
	  _ajax_post_token('../xorder/doPrinterOrder',{id:_id},function(res){
		  if(res.returnObject){
			  parent.setOrderInfo(res.returnObject);
		  }
	  });
  }
  function getTypeListAdd(){
	  _ajax_post_token('../goods/getGoodsTypeList',{pageSize:100},function(res){
		  console.log(res);
		  var list =  res.returnObject;
		  var html = "";
		  $.each(list.list,function(i,v,arr){
    		  if(list){
    			 html+='<option value="'+v.id+'">'+v.title+'</option>';
    		  }
		  })
		  $(".pIdsel").append(html);
	  })
  }
  function showEditData(){
	  _url_ = _url_edit;
	  var _id = getUrlParam("id");
	  $("#paramKey").val(_id);
	  console.log(_id);
	  _ajax_post_token(_url_id,{userType:1,id:_id},function(res){
		  console.log(res);
		 var ddt = res.returnObject;
		 ddt.priceOut = (ddt.priceOut/100).toFixed(2);
		 ddt.priceRoom = (ddt.priceRoom/100).toFixed(2);
		 ddt.goodsPackAmount = (ddt.goodsPackAmount/100).toFixed(2);
		  _showData = ddt;
	  });
  }    
      //
  /*用户-接单*/
  function member_get(obj,_id){
          //发异步删除数据
	  _url_ =_url_edit;
	  _ajax_post_token(_url_,{status:3,id:_id,shopId:spid},function(res){
	      	console.log(res);
	      	if(res.resultCode == 1000){
	      		 $(".site-doc-icon").html("");
	      		getList();
	      		layer.msg('接单成功!',{icon:6,time:2000});
	      	}else{
	      		layer.msg('接单失败!',{icon:5,time:2000});
	      	}
      });
  }
  /*用户-拒单*/
  function member_no(obj,_id){
	  //发异步删除数据
	  _url_ =_url_edit;
	  _ajax_post_token(_url_,{status:5,id:_id,shopId:spid},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			  $(".site-doc-icon").html("");
			  getList();
			  layer.msg('订单已取消!',{icon:6,time:2000});
		  }else{
			  layer.msg('操作失败!',{icon:5,time:2000});
		  }
	  });
  }
  function member_send(obj,_id){
	  	  var stat = $(obj).attr("data-status");
	  	  var st = $(obj).attr("data-st");
	  	  if(st){
	  		  if(st==31||st==32){
	  			stat = 4;
	  		  }
	  	  }
		  _url_ =_url_edit;
		  _ajax_post_token(_url_,{status:stat,id:_id,shopId:spid},function(res){
			  console.log(res);
			  if(res.resultCode == 1000){
				  $(".site-doc-icon").html("");
				  getList();
				  layer.msg('操作成功!',{icon: 6,time:1000});
			  }else{
				  layer.msg('操作失败!',{icon:5,time:2000});
			  }
		  });
  }
  //批量上架
  function member_udall(){
	  var data = tableCheck.getData().join(',');
	  _ajax_post_token(_url_edit,{status:1,ids:data},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			  $(".site-doc-icon").html("");
			  getList();
			  layer.msg('操作成功!',{icon: 6,time:1000});
		  }else{
			  layer.msg('操作失败!',{icon:5,time:2000});
		  }
	  });
  }
  function member_udall2(){
	  var data = tableCheck.getData().join(',');
	  _ajax_post_token(_url_edit,{status:2,ids:data},function(res){
		  console.log(res);
		  if(res.resultCode == 1000){
			  $(".site-doc-icon").html("");
			  getList();
			  layer.msg('操作成功!',{icon: 1,time:1000});
		  }else{
			  layer.msg('操作失败!',{icon:5,time:2000});
		  }
	  });
  }
  
  
  /*用户-启动*/
  function member_start(obj,_id){
	  layer.confirm('确认要解封此账号吗？',function(index){
		  //发异步删除数据
		  _url_ =_url_edit;
		  _ajax_post_token(_url_,{userStatus:1,id:_id},function(res){
			  console.log(res);
			  if(res.resultCode == 1000){
				  $(".site-doc-icon").html("");
				  getList();
				  layer.msg('已解封!',{icon: 6,time:1000});
			  }else if (res.resultCode == 1008){
				  layer.msg('当前账号已存在',{icon:5,time:2000});
			  }
			  else{
				  layer.msg('操作失败!',{icon:5,time:2000});
			  }
		  });
	  });
  }
      
  function updateInfo(data){
	  //发异步，把数据提交给后台
	 console.log(_url_);
	 data['shopId'] = spid;
      _ajax_post_token(_url_,data,function(res){
      	console.log(res);
      	if(res.resultCode == 1000){
      		$(".site-doc-icon").html("");
      	  parent.getList();
      	  parent.layer.msg('操作成功!',{icon:1,time:2000});
      	  x_admin_close();
          // 获得frame索引
      	}else{
      		layer.msg('操作失败!',{icon:1,time:2000});
      	}
      });
  }
      
 
      
//添加 和 修改窗口     